<script type="text/javascript" language="javascript">
    (function ($) {
        var uuid = "page-wrapper";
        var page = new $.PageDomFactory(uuid);
        var contextWindow = new $.PageWindow();

        function whenView(context, row) {
            context.detail("消息详情", row);
        }

        function whenShowRange(context, href, row){
            contextWindow.create({
                href: href + "?messageId=" + row.id,
                title: "消息发送范围"
            });
            contextWindow.open();
        }

        function whenAdd(context, href) {
            contextWindow.create({
                href: href,
                title: "发送消息",
                method: "message_add_save",
                callback:function(status){
                    if(status){
                        context.grid.datagrid("reload");
                    }
                }
            });
            context.grid.datagrid('clearSelections');
            contextWindow.open();
        }

        var pageComponentList = new $.PageListComponent(uuid, {
            view: {
                grid: "grid",
                myToolbar: "nsdb",
                colbar: "template"
            },
            configs: {
                gridTitle: "消息列表",
                gridUrl: '${pageContext.request.contextPath}/app/api/message/sendList',
                gridColumns: [
                    {
                        field: 'id',
                        checkbox: true
                    },
                    {
                        field: 'temp1',
                        hidden: true
                    },
                    {
                        field: 'message.sendTitle',
                        title: '消息标题',
                        width: 200,
                        align: 'left'
                    },
                    {
                        field: 'message.sendContent',
                        title: '消息内容',
                        hidden:true,
                        width: 150,
                        align: 'left'
                    },
                    {
                        field: 'message.messageType',
                        title: '消息类型',
                        width: 100,
                        align: 'left',
                        formatter: function (value, rowData, rowIndex) {
                            if (value == 'MESSAGE_TYPE_SYSTEM') {
                                return '系统消息';
                            } else {
                                return "私信"
                            }
                        }
                    },
                    {
                        field: 'result',
                        title: '消息发送情况',
                        width: 150,
                        align: 'left',
                        formatter: function (value, rowData, rowIndex) {
                            return "总数：" + rowData.sendTotal + "条，已读：" + rowData.readTotal + "条";
                        }
                    },
                    {
                        field: 'message.sendedTime',
                        title: '消息发送时间',
                        width: 100,
                        align: 'left'
                    }
                ]
            },
            events: {
                renderColBarBefore: function () {
                    return true;
                },
                onClickColBtn: function (context, btn, row) {
                    switch (btn.key) {
                        case "view":
                            whenView(context, row);
                            break;
                        case "range":
                            whenShowRange(context, btn.href, row);
                            break;
                        default :
                            break;
                    }
                },
                onClickToolbarBtn: function (context, btn, id) {
                    switch (btn.key) {
                        case "add":
                            whenAdd(context, btn.href);
                            break;
                        case "del":
                            context.del(btn.href);
                            break;
                        case "search_all":
                            context.searchAll();
                            break;
                        case "search":
                            context.search(btn.href, "消息搜索", "message_search");
                            break;
                        default :
                            break;
                    }
                }
            }
        });
    })(jQuery);
</script>